use strict;
use warnings;

package My::Widget::BannerImageGenerator;
use Data::Dumper;
use Digest::SHA1 qw(sha1_hex);
use Cwd qw(abs_path);

sub new {
    my ( $class, %params ) = @_;
    my $self = {};
    bless( $self, $class );

    # constructor params to attribute key map
    my $param_attribute_map{ image_path => 'image_path', };

    # by convention parameters ending with '_path' or '_file' are paths
    foreach my $key ( keys(%params) ) {
        my $value = $params{$key};
        if ( $key =~ /_(?:path|file)$/ ) {
            $value = abs_path($value);
        }

        # if a mapping entry doesn't exist then we use the parameter name as the attribute name
        $key = ( exists( $param_attribute_map->{$key} ) ? $param_attribute_map->{$key} : $key );
        $self->{$key} = $value;
    } ## end foreach my $key ( keys(%params) )

    return $self;
} ## end sub new

sub eval_cache_filename {
    my ( $self, %params ) = @_;
    my @tokens;
    my $param_dumper = Data::Dumper->new( [ $params{params} ] );
    $param_dumper->SortKeys(1);
    push @tokens, $param_dumper->Dump;
    push @tokens, $params{ino};
    return sha1_hex( join( chr(0), @tokens ) );
} ## end sub eval_cache_filename
1;
